package org.leetcode.easy.leetcode455;

import java.util.Arrays;

public class Solution {


    public int findContentChildren2(int[] g, int[] s) {
        int count = 0;
        Arrays.sort(g);
        Arrays.sort(s);

        int n1 = g.length;
        int n2 = s.length;
        int index = 0;

        for (int i = 0; i < n2; i++) {
            int minSize = s[i];
            for (int j = index; j < n1; j++) {
                if (minSize>=g[j]){
                    count++;
                    index=j+1;
                    break;
                }
            }
        }

        return count;
    }
    public int findContentChildren(int[] g, int[] s) {
        int count = 0;
        Arrays.sort(g);
        Arrays.sort(s);

        int n1 = g.length;
        int n2 = s.length;

        for (int i = 0; i < n1; i++) {
            int temp = g[i];
            for (int j = 0; j < n2; j++) {
                if (temp<=s[j]){
                    count++;
                    s[j]=0;
                    break;
                }
            }
        }

        return count;
    }
}
